package com.ram.controller;

import com.ram.pojo.RepairRequest;
import com.ram.pojo.Result;
import com.ram.service.RepairRequestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ram.pojo.RepairRequestQueryParam;

@RestController
@RequestMapping("/repair/request")
public class RepairRequestController {
    @Autowired
    private RepairRequestService service;
    @GetMapping("/list")
    public Result list() { return Result.success(service.list()); }
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) { return Result.success(service.getById(id)); }
    @PostMapping
    public Result add(@RequestBody RepairRequest request) { service.add(request); return Result.success(); }
    @PutMapping
    public Result update(@RequestBody RepairRequest request) { service.update(request); return Result.success(); }
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) { service.deleteById(id); return Result.success(); }
    @PostMapping("/page")
    public Result pageQuery(@RequestBody RepairRequestQueryParam param) {
        return Result.success(service.pageQuery(param));
    }

    /**
     * 审核报修单（通过/驳回）
     */
    @PostMapping("/audit")
    public Result audit(@RequestParam Integer id, @RequestParam Boolean pass, @RequestParam(required = false) String remark) {
        service.audit(id, pass, remark);
        return Result.success();
    }

    /**
     * 派单
     */
    @PostMapping("/assign")
    public Result assign(@RequestParam Integer id, @RequestParam Integer assigneeId, @RequestParam String assigneeName) {
        service.assign(id, assigneeId, assigneeName);
        return Result.success();
    }

    /**
     * 完工
     */
    @PostMapping("/finish")
    public Result finish(@RequestParam Integer id) {
        service.finish(id);
        return Result.success();
    }
} 